﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace ConsoleApi.AllError
{
    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class GloabIExcptionfilter : IExceptionFilter
    {
        private readonly ILogger<GloabIExcptionfilter> logger;

        public GloabIExcptionfilter(ILogger<GloabIExcptionfilter> logger)
        {
            this.logger = logger;
        }

        public void OnException(ExceptionContext context)
        {
            try
            {

                logger.LogError("全局异常报错" + context.Exception.Message);
                context.ExceptionHandled = true;
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);
                throw;
            }
        }
    }
}
